/*
 * author      : dormi330
 * date        : 2018/6/26
 * project     : mybatis
 * description : 购物车 应用层服务, 代理到真实到服务
 */

package com.deep.trade.application;

import com.deep.trade.adaptor.required.member.Member;
import com.deep.trade.adaptor.required.member.MemberService;
import com.deep.trade.application.cart.CartQueryService;
import com.deep.trade.application.cart.CartService;
import com.deep.trade.cart.CartFacade;
import com.deep.trade.cart.dto.InDtoCart;
import com.deep.trade.cart.dto.InDtoCartDelete;
import com.deep.trade.cart.CartQueryFacade;
import com.deep.trade.cart.dto.OutDtoCartItem;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CartFacadeImpl implements CartFacade, CartQueryFacade {
    private CartService cartService;
    private MemberService memberService;
    private CartQueryService cartQueryService;

    @Autowired
    public CartFacadeImpl(
            CartService cartService
            , MemberService memberService
            , CartQueryService cartQueryService
    ) {
        this.cartService = cartService;
        this.memberService = memberService;
        this.cartQueryService = cartQueryService;
    }
    //========================================== CartFacade ==========================================//

    /**
     * 添加sku到购物车
     */
    @Override
    public void addSkuToCart(InDtoCart inDtoCart) throws Exception {
        cartService.addSkuToCart(inDtoCart);
    }

    /**
     * 从购物车 删除一个sku
     */
    @Override
    public void removeSkuFromCart(InDtoCartDelete inDtoCartDelete) throws Exception {
        cartService.removeSkuFromCart(inDtoCartDelete);
    }

    /**
     * 修改购物车 sku数量
     */
    @Override
    public void alterQuantity(InDtoCart inDtoCart) throws Exception {
        cartService.alterQuantity(inDtoCart);
    }
    //========================================== CartFacade ==========================================//


    //========================================== CartQueryFacade ==========================================//

    /**
     * 查看 购物车 列表
     */
    @Override
    public PageInfo<OutDtoCartItem> cartListOfMember(int pageNum, int pageSize) throws Exception {
        Member member = memberService.memberOfToken();
        return cartQueryService.cartListOfMember(member, pageNum, pageSize);
    }
    //========================================== CartQueryFacade ==========================================//

}
